<?php
class models_quangcao extends connect{
	
	function _listquangcao()
	{
		$sql = 'SELECT MaQC,TenQC,Hinh,Url,ViTri,AnHien FROM quangcao';
		$this-> query_db($sql);
		return $this->fetchAll();
	}
	function listquangcao()
	{
		$sql = 'SELECT MaQC,TenQC,Hinh,Url,ViTri,AnHien FROM quangcao
				WHERE AnHien=1';
		$this-> query_db($sql);
		return $this->fetchAll();
	}
	function listquangcaoright()
	{
		$sql = 'SELECT MaQC,TenQC,Hinh,Url,ViTri,AnHien FROM quangcao
				WHERE AnHien=1 AND ViTri=0';
		$this-> query_db($sql);
		return $this->fetchAll();
	}
	function listquangcaoleft()
	{
		$sql = 'SELECT MaQC,TenQC,Hinh,Url,ViTri,AnHien FROM quangcao
				WHERE AnHien=1 AND ViTri=1';
		$this-> query_db($sql);
		return $this->fetchAll();
	}
	
	function _addquangcao($TenQC,$Hinh,$Url,$ViTri,$AnHien)
	{
		$sql = "INSERT INTO quangcao VALUES ('','$TenQC', '$Hinh','$Url','$ViTri','$AnHien')";
		$this->query_db($sql);
	}
	function _delquangcao($id){
		$sql = "
				DELETE 
				FROM quangcao
				WHERE MaQC = '$id'";
		$this->query_db($sql);
	}
	function _getquangcao($id){
		$sql = "
				SELECT MaQC,TenQC,Hinh,Url,ViTri,AnHien
				FROM quangcao
				WHERE MaQC = '$id'";
		$this->query_db($sql);
		return $this->fetchOne();
	}
	function _updatequangcao($TenQC,$Hinh,$Url,$ViTri,$AnHien,$id){
		$sql = "UPDATE quangcao
				SET 
				    TenQC= '$TenQC',
				    Hinh = '$Hinh', 
				    Url  = '$Url',
				    ViTri  = '$ViTri',
					AnHien = '$AnHien'
					WHERE MaQC = '$id'";
		$this->query_db($sql);
	}
}
?>